var express = require('express');
var router = express.Router();

/* GET home page. */

function hook(data,fn){
	return fn+"("+JSON.stringify(data)+")";
}
router.get('/list', function(req, res, next) {
	var callback = req.query.callback;
	var data = {
		
	}
  res.send(hook(data,callback));
  res.end();
});

router.get('/products', function(req, res, next) {
	var callback = req.query.callback;
	var page = req.query.page;
	var category = req.query.category;
	var type = req.query.type;
	var has_more = true;
	var array =[];
	if(page == 2){
		has_more = false;
	}
	var imgs = [
		'https://onegoods.nosdn.127.net/goods/2493/1d7ad0dbd1d501cdb7f52c2bdbd79323.jpg',
       'https://onegoods.nosdn.127.net/goods/2493/9a56d87488bc52e1088a32d1aa67460f.jpg',
        'https://onegoods.nosdn.127.net/goods/2493/5ff95e735ec589009f19d807cdc1769c.jpg',
        'https://onegoods.nosdn.127.net/goods/2493/21cd867b0cf517d501fd10ead5fe1b60.jpg',
        'https://onegoods.nosdn.127.net/goods/2493/3146c58fc5989cab224ba9d56d6c3e5e.jpg',

	];
	for(var i=0;i<10;i++){
		array.push({
			id:"123",
			img:imgs[i%5],
			name:category +" "+type+" "+"苹果手机系列 iphone"+(page*10+i+1),
			value:17680,
			stock:9786,	
		});
	}
	var data = {
		data:array,
		has_more:has_more//是否是末页了
	}
	var str = hook(data,callback);
   res.send(str);
  res.end();
});

module.exports = router;
